import GameConst from "./GameConst";
import Utils from "./utils";
import FieldObject from "./FieldObject"
import MenuManager from "./menumanager";

export default class LevelManager {
    constructor() {
        this.data = [];
        this.currentLevel = 0;
        this.maxLevel = 0;
        
        this.isFirstLoad = true;
        this.lastOpened = 0;
        this.moves = 0;
        this.bonuses = 0;
        LevelManager.instance = this;
        GameConst.levelManager = this;
        var levelcfg = GameConst.levelData;
        GameConst.LEVEL_AMOUNT = levelcfg.length;
        for (var lvl = 0; lvl < GameConst.LEVEL_AMOUNT; ++lvl) {
            var cfg = lvl < levelcfg.length ? "=" + levelcfg[lvl] : null;
            this.data.push(new LevelData(lvl, cfg, lvl == 0 ? GameConst.OPENED_STATE : GameConst.CLOSED_STATE));
        }
        this.load();
        this.lvl10 = {};
    }

    save() {
        var data = {
            version: GameConst.SaveVersion,
            moves: this.moves,
            bonuses: this.bonuses
        };
        var t = [];
        var total = 0;
        var stars = 0;
        for (var n = 0; n < this.data.length; ++n) {
            var r = this.data[n];
            t.push({
                c: r.state,
                s: r.stars,
                p: r.score
            });
            
            total += r.score;
            stars += r.stars;
        }
        data.levels = t;
        if (this.isLocalStorageAvailable()) {
            localStorage.setItem("save", JSON.stringify(data));
        }
        var toprank = {
            "score": total,
            'stars': stars            
        };
        GameConst.adapter.save(toprank);
        var lvl = this.data[this.currentLevel];
        var lvlValue = {
            'v': lvl.score,
            'dt': Laya.timer.currTimer
        };
        GameConst.adapter.saveLvlData( this.currentLevel, lvlValue);
    };
    
    load() {
        var dataStr = false;
        if (this.isLocalStorageAvailable()) {
            dataStr = localStorage.getItem("save");
            if (!dataStr)
                return;
            dataStr = JSON.parse(dataStr);
            var levels = dataStr.levels;
            if (!levels)
                return;
            if (GameConst.SaveVersion != dataStr.version) {
                localStorage.clear();
                return;
            }
        }
        if (!dataStr) {
            return;
        }
        this.moves = Math.max(this.moves, dataStr.moves);
        this.bonuses = Math.max(this.bonuses, dataStr.bonuses);
        for (var i = 0; i < levels.length; ++i) {
            this.data[i].state = levels[i].c;
            this.data[i].stars = levels[i].s;
            this.data[i].score = levels[i].p;
            if (this.data[i].state >= GameConst.OPENED_STATE)
                this.lastOpened = Math.max(this.lastOpened, i);
        }
        this.maxLevel = this.currentLevel = this.lastOpened;
        if (this.maxLevel < GameConst.LEVEL_AMOUNT - 1 && this.data[this.maxLevel].stars > 0) {
            this.maxLevel++;
        }
        this.isFirstLoad = false;
    };

    maxLvl() {
        this.maxLevel = this.currentLevel > this.maxLevel ? this.currentLevel : this.maxLevel;
        return this.maxLevel;
    }

    isLocalStorageAvailable() {
        try {
            localStorage.setItem("test", "test");
            localStorage.removeItem("test");
            return "localStorage" in window && window["localStorage"] !== null;
        } catch (e) {
            return false;
        }
    }

    openNext() {
        if (this.data[this.currentLevel].stars > 0) {
            if (this.currentLevel < GameConst.LEVEL_AMOUNT - 1) {
                this.currentLevel++;
                var t = this.data[this.currentLevel].state;
                this.data[this.currentLevel].state = Math.max(GameConst.OPENED_STATE, this.data[this.currentLevel].state);
                //this.lastOpened = Math.max(this.lastOpened, this.currentLevel);
                if (t == GameConst.CLOSED_STATE) {
                    MenuManager.instance.map.levelToUnlock = this.currentLevel;
                }
            }
            //this.save();
        }
    }

    loadNextLevel() {
        //this.openNext();
        if (this.currentLevel < GameConst.LEVEL_AMOUNT - 1) {
            this.prepareToLoadLevel(this.currentLevel);
        }
    };

    onLevelComplete(stars, score) {
        MenuManager.instance.winMenu.setStarData(stars);
        this.data[this.currentLevel].state = GameConst.COMPLETED_STATE;
        this.data[this.currentLevel].stars = Math.max(stars, this.data[this.currentLevel].stars);
        this.data[this.currentLevel].score = Math.max(score, this.data[this.currentLevel].score);
        this.save();
        this.openNext();
    };

    loadLevel(lvl) {
        MenuManager.instance.closeCurrent();
        this.lastOpened = this.currentLevel = lvl;
        GameConst.level.init(lvl);
        GameConst.adapter.loadLvlData(lvl);
    };




    restartLevel() {
        this.prepareToLoadLevel(this.lastOpened);
    };

    prepareToLoadLevel(lvl) {
        MenuManager.instance.transition.play(null, -1);
        this.loadLevel(lvl);
    };

}


Object.defineProperty(LevelManager.prototype, "totalScores", {
    get: function () {
        var e = this.data.length;
        var t = 0;
        for (var n = 0; n < e; ++n)
            t += this.data[n].score;
        return t;
    },
    enumerable: true,
    configurable: true
});
Object.defineProperty(LevelManager.prototype, "totalStars", {
    get: function () {
        var e = this.data.length;
        var t = 0;
        for (var n = 0; n < e; ++n)
            t += this.data[n].stars;
        return t;
    },
    enumerable: true,
    configurable: true
});



// LevelManager.prototype.restartLoadNextLevel = function () {
//     //        console.log("3"+this.currentLevel);
//     this.data[this.currentLevel].state = GameConst.COMPLETED_STATE;
//     if (this.currentLevel < GameConst.LEVEL_AMOUNT - 1) {
//         var t = this.data[this.currentLevel + 1].state;
//         this.data[this.currentLevel + 1].state = Math.max(GameConst.OPENED_STATE, this.data[this.currentLevel + 1].state);
//         this.lastOpened = Math.max(this.lastOpened, this.currentLevel + 1);
//         if (t == GameConst.CLOSED_STATE)
//             MenuManager.instance.map.fastUnlock(this.currentLevel + 1);
//     }
//     this.save();
// };







// LevelManager.levelDatas = [




//     "00001000030404100000001000100103100310010000030401030404030400030303040201010401000003030402010104030000010402030101010300000104010403020300000003040301040301040010001003041003100000001000000100100000-4-200-1-200-300-400-10-1111111111--1111111111",
//     "00000000000400000000000000020102011010101010100103040301010100040103030403101010000001030203030302030000040303030203030310101002010201020401000000000000041010101010100000000000000000000000000000000000-4-550-1-550-650-820-12-1111111111--1111111111",

//     "00000000000000002020000000000000000000200000000000000000000000000020202020200203000020208004202020040000202004802020200300000020202020200102000000030202010200000000000104048304022000000003040402012020-0-800-1-900-1400-1800-33-1111111111--1111111111",
//     "00000000000000021010000000001000040403101010101010100101020300000000100203010102000000000401010401010000000002010401010200000000100101010304101010101010030202030000000010020104041000000000000002011010-4-1100-1-1000-1300-1500-25-1111111111",
//     "00000000000000000000000000000000000000000000000003020402020000000202040101010300020402010101040302000301010102040200000002040303040000000000202020202020202020200000000000000000000000000000000000000000-4-800-1-800-1100-1500-18-1111111111-0900801019019011-1111111100",

//     "00000000000000000000000040404040404040400000402020302030304000004020203020303040000040303030202020400000402020203030304000004030302030202040000040303020302020400000404040404040404000000000000000000000-0-1300-1-2500-3200-3800-55-1111111111--1111111111",


//     "00000000000000020102000000000000000102010000001010101002010200000010000010010201000000000000000201020000000000000001020100000010000010020102000000101010100102010000000000000002010200000000000000010201-3-45-1-1400-1900-2600-42-1111111111",
//     "00002000002000002000000020000020000020000000200000200000200000032000002000002000000320000020000020000003200000200000200000032000002000002000000020000020000020000000200000200000200000002000002000002000-4-1500-0-1500-1700-1900-25-1111111111",
//     "00000000000000002020000000000000000000200000200000000020000000000020202020000000000000200404200000000000002004042000000000000020202020000000000020000000002000000000000000000000002000000000000000002020-0-1500-1-1500-2500-3500-38-1111111111",
//     "00000000000000000000000000002010101010000000000020202020100000000000202020200000000000002020202000000000000020202020000000000000202020200000000000002020202010000000000020101010100000000000000000000000-0-1500-1-1400-2000-3200-38-1111111111",
//     "00030220000000000000000204200000000000000004032000000000000000030220000000000000202020202020202020202020202020202020202000000000020120000000000000000403200000000000000002012000000000000000010420000000-3-35-1-1500-1800-2100-30-1111111111",
//     "00002000200020002010000010200020002000200000200020002000201000001020002000200020000020002000200020100000102000200020002000002000200020002010000010200020002000200000200020002000201000001020002000200020-0-1500-1-2500-3000-3900-65-1111111111",
//     "10202020202020202010001020202020202010000000002020202000000000000000202000000000000000000000000000000000000000000000000000000000202000000000000000202020200000000010202020202020100010202020202020202010-3-65-0-2000-2500-3200-50-1111111111",
//     "00000010001000000000000000001000000000000000001000100000000000000000100000000000000000100010000000000000000010000000000000000010001000000000000000001000000000000000001000100000000000000000100000000000-2-2-1-1600-2400-3700-45-0101010101",
//     "00000000202020000000000000000020202000000000000000002020200000000000002020200000000000002020200000000000000000202020000000000000000020202000000000000000002020200000000000000000202000000000000000202020-2-2-1-2700-3800-4900-60-1111111111",
//     "00000000000000000000002020000000200000000020201000000020000000001020200000002000000000202010000000202000000010202000000000200000002020100000000020000000102020000000002000000020200000000000000000000000-0-2500-1-2500-3100-3700-45-1111111111",
//     "00000000202000000000000000002020000000000000000020200000000000000000202000000000101010102020202020201010101020202020202000000000202000000000000000002020000000000000000020200000000000000000202000000000-2-2-1-2200-3200-4100-55-0110000110",
//     "00000000000000000000000000002020000000000000001020201000000000000000202000002020000000000000001020200000000000000010202000000000202000002020000000102020100000000000000020200000000000000000000000000000-3-70-3-2000-2800-3400-48-1111111111",
//     "00000000000000000000000000000000000000001010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000-2-2-1-3500-4500-5500-62-1100000000",
//     "00000000000000000000000000000000000000000000201010101010101000002020505050505051000020205000000000510000202050000000005100002020505050505051000020101010101010100000000000000000000000000000000000000000-1-1-1-1800-2500-3300-30-1100000000",
//     "20200000000020205050202000000000202050500000000000002020202000000000000020202020000000000000000000002020202020000000000020202020200000000000505050202000002020205050502020000020202050505020200000202050-1-1-1-1400-2700-3500-35-1111111111",
//     "10511052105310541051105110521053105410512020202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000202020202020202020201051105210531054105110511052105310541051-1-1-1-3000-3900-4800-55-1111111111",
//     "10101010101010101010101020202020202020201020000000000000000000200020002000200020200020002000200020000020002000200020002020002000200020002000102000000000000000001010202020202020202010101010101010101010-2-3-1-3500-4500-5900-55-0001111000",
//     "00000000000000000000000000105020001050200000001050200010502000105020001050200000001050200010502000000000001050200010502000000010502000105020001050200010502000000010502000105020000000000000000000000000-1-1-1-2300-3200-4500-55-0001111000",
//     "00000000000000001054000000000000000010530000000000000000105100000000000000001052000000000000000010140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000-1-1-1-2700-3600-4900-50-1111111111",
//     "00105010501050100010005050505050505050000000000000000000501000000000000000005050000000000000000050100000000000000000501000000000000000005050000000000000000050100050505050505050500000105010501050100010-1-1-1-3800-4500-5900-55-1111111111",
//     "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010101010101010101010501010505050501010505050505050505050505050505050101050505050-1-1-1-2500-3200-3800-40-1111111111",
//     "00202010000000000020002020102000000000200020202020200000002000202010202020002020002020202020200020200020202020202000202000202010202020002020002020202020000000200020201020000000002000202010000000000020-0-2500-1-2300-3100-4300-48-1111111111",
//     "04042050202020502020100420202050202020501010205020202050202010001020205020202050100000102020205020201000000010502020205010000000001020502020100000000000102020501000000000000010202010101010101010101050-1-1-1-2900-3500-4300-45-1111111111",
//     "10000010505050500000100010505050505000001010505050505050000010202010101010100000000000000000000000000000000000000000000010202010101010100000101050505050505000001000105050505050000010000010505050500000-1-1-1-2500-3400-4300-45-1111111111",
//     "00000000000000000000000000000000000000000000000000303030303000000000002020202030000000000020202020300000000000202020203000000000002020202030000000000030303030300000000000000000000000000000000000000000-0-1-1-2200-2800-4000-48-1111111111",
//     "00000000000000302050000000000000003020500000000000000030205000003030303030303050000000000000000000500000000000000000005000003030303030303050000000000000003020500000000000000030205000000000000000302050-1-1-1-2000-3100-4100-42-1111111111",
//     "50505020000020205050505020200000205050505050502000002020505050502020000020505050505050200000202050505050202000002050505050505020000020205050505020200000205050505050502000002020505050502020000020505050-1-1-1-2500-3300-4200-40-0110000110",
//     "00000000000000000000000000005555555500000000000055606030000000000000556060300000000000005555555500000000000000000000000000555555550055555555005560603000556060300055606030005560603000555555550055555555-1-1-1-2500-3300-4500-60-1111111111",
//     "30303020000020300000000030200000203000000000302000002030000030303020202020303030202020303030302020200000203000003020000000002030000030200000202020303030302020203030302020202030303000003020000020300000-2-1-1-2600-3600-4400-58-0110011000",
//     "00003053300000000000000030303000000000000000000000000000000000000000000000101010000000000000001051100000000000000010101000000020202000000000000000205220000000000000002020200000000000000000000000000000-1-1-1-1600-2000-2600-25-1111111111",
//     "00000000000000000000000000000000000000000000000000000000000020302030203020302030501050501050501050505010505010505010505030203020302030203020000000000000000000000000000000000000000000000000000000000000-1-2000-1-2800-3600-4500-52-1111111111",
//     "00000000000000000401000000303030303030040000300303030303300100300303030303300104003003033003030330010030030303030330010400300303300303033001000030030303033001040000003030303030300100000000000000000104-3-50-3-2000-2600-3000-21-1111111111",
//     "30300201040304010230003030020402010330300000303030033030300000000000303030000000000000000000000000000000000000000000002020200000000000202020042020200020202003040302042020200103020101020301020402040301-4-2200-1-2000-2600-3400-23-1111111111",


//     "00101000000000000000100000100000000000101000001000000000100000101000000000001000000000000000000000100000000000101000000000000000100000100000000000001000001000001000000000101000000000100000000000000000-3-33-2-1600-1900-2200-35-1111111111",
//     "00000000000003032020000000000000000320200000000000000000202000000000000000002020000000000000000020200000000000000000202000000000000000002020000000000000000020200000000000000004202000000000000004042020-0-1500-1-1800-2300-2500-40-1111111111",
//     "00000020000000200000000000002000200000000000000000200000000020000000200020000000002000200000002000200000200000000000200000200020000000200020200000002000200000000000000000200000000000000000200020000000-2-2-1-2700-3500-4800-65-1111111111",
//     "00000000000000200000002010001000001000000000000020000000002000100000000020100010002000000000000000000000001020000010000010200000000000200000000000002000000000100020000010001020002000100000000000000000-4-1700-1-1700-1900-2200-35-1111111111",
//     "10000000000000000000000020505000205050000000205050002050500200002050500020505401100020505000205351011000205050002051510100002050500020535101000020505000205054010000205050002050500210000000000000000000-1-1-1-2000-2600-3600-38-1111111111",
//     "00000000000000000000100010001000100010001000100010001000100000000000000000000000001020001020001020000020200020200020200000202000202000202000002020002020002020000010200010200010200000000000000000000000-3-50-1-2000-2500-3000-50-1111111111",
//     "00000000000000000000000000000000000000000000505050505050000000005000000000500000000050005050005000000000500050500050000000005000000000500000000050505050505000000000000000000000000000000000000000000000-1-1-1-1800-2100-2700-26-1111111111",
//     "00000020000000101010000000202000000010100000000020200000001000000000002020000050101010101010502000501010101010105020005000000000002020000050000000002020000000100000002020000000101000000020000000101010-1-2000-1-1000-1900-2700-45-1111111111",
//     "00000000000000000000000030303000202020000000305050002050500000003030300020505000000000000000202020000000202020000000000000002050500030303000000020505000305050000000202020003030300000000000000000000000-1-1-1-2100-3000-3400-35-1111111111",
//     "00300000300000300000200030000030000030000020003000003000003000002000300000300000200000200030000030000020000020003000003000002000002000300000200000200000200030000020000020000020003000002000002000002000-0-1-1-2000-3000-3600-40-1111111111",
//     "00000000000000000000000000000000000000300000000000000000301000000000000000301050000000000000301050500000000000303050505000000000000030105050000000000000003010500000000000000000301000000000000000000030-1-2000-1-3500-4200-4700-45-1111111111",
//     "00000000000000000000000030303010303030000000305050005050300000003050500050503000000010000000000010000000100000000000100000003050500050503000000030505000505030000000303030103030300000000000000000000000-1-1-1-2000-2700-3700-50-1111111111",
//     "00200000000505000000200020000005050000000020000000050500000020002000000505000000002000000005050000002000200000050500000000200000000505000000200020000005050000000020000000050500000020002000000505000000-2-2-1-3200-4200-5500-60-1111111111",
//     "00000040000000400050000000400000004000500000004000000040005000000040000000400050000000101010101000501010101000000010101000000040000000400050000000400000004000500000004000000040005000000040000000400050-1-3-1-2800-3400-4500-62-1111111111",
//     "00000000301055105510000000003020505050550000000030200000501000000000302000005055000000003020000050100000000030200000501000000000302000005055000000003020000050100000000030205050505500000000301055105510-1-1-1-3500-4300-5900-68-1100000000",
//     "00000020550000000000000000205500000000000000002055000000100000000020550000101010000000205500005555550000002055000055555500000020550000101010000000205500000010000000002055000000000000000020550000000000-1-1-1-3500-4200-5300-55-1100000000",
//     "00000000000000000000000000000000000000000005050505050505050020002010200000000000102010201020000000202010200020102000201000000000002010201020000000000000201020000005050505050505050000000000000000000000-3-50-0-2200-3000-3700-45-1111111111",
//     "00000020050000000000000000200505000000000000000020050000000000000000200500000000000000002005050000000000000000200500000000000000002005000000000000000020050500000000000000002005000000000000000020050000-2-3-1-4000-4500-5700-55-1111111111",
//     "00000000000000000000000000000000000000000000050500000505000000400555505055050000004000505555500000000040005055555000000000400555505055050000000005050000050500000000000000000000000000000000000000000000-1-1-1-1400-2100-2600-30-1100000000",
//     "00002020202020205030000055555555555550300000553030303030503000005555555555555030000020202020202050300000202020202020503000005555555555555030000055303030303050300000555555555555503000002020202020205030-1-1-1-4000-4600-5600-65-1100000000",
//     "00004000000000200040002000300000000030000000000000000000000000000030003000000030000020000000400020000000004000200000004040000000000000000000002000002000000030003000004000300020000000000000000000004000-4-3400-1-3300-3800-4200-35-1111111111",
//     "00000060000000000030000000500000000000306050000050000000003000500000005050000030000050500000005050306050005000505050503000000050505050500030505050000050000000306000000050600000003000000060000000000030-1-3400-1-2500-3100-4100-38-1111111111",
//     "00000000000010101010000000000000100060500000000000004000005000000000000010101010000000000000100000500000000000004000605000000000000010000050000000000000101010100000000000004000005000000000000010006050-1-3400-1-5000-6500-7500-90-1111111111",
//     "00000000202060505050000000000020206050500000000000002020605000000000000000202060000000000000000020200000000000000000002000000000000000000030000000000000000030300000000000000030305000000000000030305050-1-3400-1-3000-3500-3900-45-1111111111",
//     "00000000000000000010000000000000000010600000000000000010605000000000000010605050000000000000001050500000000000001060505000000000000000106050000000000000000010600000000000000000001000000000000000000010-1-3400-1-4000-5200-6200-65-1111111111",
//     "00000000002020300040000000000020200030000000000000202030004000000000002020003000000000000020203000400000000000202000300000000000002020300040000000000020200030000000000000202030004000000000002020003000-2-3-1-4500-6200-7500-75-0011111100",
//     "00000000000020100000000000000000203010000000000000002030501000000000000020305060000000000000203050600000000000002030506000000000000020305060000000000000203050100000000000002030100000000000000020100000-1-3400-1-3800-4500-5300-55-1111111111",
//     "10101010101010101010005050505050505050100050606060606060501000506050505050605010005060506060506050100050605060605060501000506050505050605010005060606060606050100050505050505050501010101010101010101010-1-1-1-2500-4000-5000-50-1111111111",
//     "00000000000000000000004040404040404040000040303030303030400000404040404040304000000000002020403040000000000020204030400000202020000040304000002020200000403040000020202000004040400000000000000000000000-3-65-2-3000-4500-5600-48-1111111111",
//     "50501010101010105050505050503030505050500050502020202050501000502020303020205010003020303030302030100030203030303020301000502020303020205010005050202020205050105050505030305050505050501010101010105050-1-1-1-2900-4000-5400-65-1111111111",
//     "30302020200000000000003030202020000000000000303020202000000000000030302020200000000000003020202000000000000030202020000000000030302020200000000030302020200000000030302020200000000030302020200000000000-0-1-1-2500-3800-4500-48-1111111111",
//     "00000000000000000000030201020304101010100104032020203030303003020201020330405050010401202020304050500402032020203040505002010402030430405050040103202020303030300102020401031010101000000000000000000000-1-2000-1-2200-2700-3700-45-1111111111",
//     "00000000000000203010000000000000203010500000000000203010505000000000203010505000000000203010505000100000203010505000101000203010505000101000203010505000101000003010505000101000000010505000101000000000-1-1-1-1800-2900-3800-70-1111111111",


//     "00000000000000000000000020002020002000000000200020200020000000000000000000000000202020202020202020202020202020202020202000000000000000000000000020002020002000000000200020200020000000000000000000000000-0-800-1-1200-2000-2500-45-1111111111-09006010190170112902801239039013-1111110000",
//     "10100000000000001010100000000000000000100000000020200000000000000020202020000000000020303020203000000000203030202030000000000030303030000000000000003030000000001000000000000000001010100000000000001010-0-800-1-1500-2500-3500-50-1111111111--0011111100",
//     "00000000202000000000000000002020200000000000202000003030000000002020200030302000202000203030000020202020000030302000202000203030002020200000000030300000202000000000002020200000000000000000202000000000-0-800-1-1500-2500-3500-50-1111111111--1111111111",
//     "00000000000000208080000000000000002010800000000000000000202000000000000000002080000000000000000020800000000000000000208000000000000000002080000000000000000020200000000000000020108000000000000000208080-4-2700-1-2700-3200-3500-50-1111111111--1111111111",
//     "00000000008020300000000000000080302000000000000000802030000000000000008030200000000000000080203000000000000000803020000000000000008020300000000000000080302000000000000000802030000000000000008030200000-0-2700-1-2700-3500-4000-50-1111111111--1111111111",
//     "00000000000020000000200000000020302000003020000020300030200020000000002030200000000000000000200000800000002000000000008000002030200000000020002030003020000020300000203020000000002000000020000000000000-0-2700-1-2700-3500-4000-53-1111111111--1111111111",
//     "00000000000000000000201020202010200000001010102010101000000020102020201020000000000000008000800000000000008000800000000000000020102020201020000000101010201010100000002010202020102000000000000000000000-0-2700-1-2700-3500-4000-50-1111111111--1111111111",
//     "00002020203030300000000020505050305000000000205050505050000000002020203000000000000000000000000000000000000000000000000000000000302020200000000050505050502000000000503050505020000000003030302020200000-1-2700-1-2000-2500-3000-35-1111111111--1111111111",
//     "20202020202020202020205050505050505050002050505050505000000020505050000000000000000000000000000000000000000000000000000020505050000000000000205050505050500000002050505050505050500020202020202020202020-1-2700-1-2000-2500-3000-35-1111111111--1111111111",
//     "00000000000000000000000000000000000000000000303030303030300300003001020401023004000030023030300330030000300330803003300100003004020130023001000030303030300030020000000000000000000000000000000000000000-5-2700-1-2000-2500-3000-40-1111111111--1111111111",
//     "00000010000010000000000000100000105050500000001000001050605000000010000010505050000000101010100000000000002000002000000000000020000020000000000000200000200000000000002000002000000000000020000020000000-1-2700-1-2000-2500-3000-40-1111111111-02005010120160112202701232038013420490145905071569061716790727178908371899094719-1111100000",
//     "00000000000000000000000000000000000000000010101010101010202000100000000000202020001000000000202020200010000000002020202000100000000000202020001010101010101020200000000000000000000000000000000000000000-0-2700-1-1800-2500-3000-35-1111111111-09003210190142118902521299036213-1111111111",
//     "00000000308030505050000000308020803050500000000030803000005000000000003000000050000000000000000000500000000000000000005000000000003000000050000000003080300000500000003080208030505000000000308030505050-1-2700-1-1800-2500-3000-45-1111111111--1111111111",
//     "10100000000000001010100000000000000000100000000060608000000000000060505060800000000060506060506000000000605060605060000000000060505060800000000000006060800000001000000000000000001010100000000000001010-1-2700-1-1800-2500-3000-40-1111111111--1111111111",
//     "00000000000000000000000000000000000000001010103030303030303000000020200020200000000000202000202000000000002020002020000000000020200020200000101010303030303030300000000000000000000000000000000000000000-3-60-1-1800-2500-3000-40-0001111000-39000010490110115902801269039013-0001111000",
//     "00000000000000209090000000000000209090900000000000209090902000000000209090902000000000209090902000000000209090902000000000209090902000000000209090902000000000009090902000000000000090902000000000000000-1-60-1-2300-3200-4000-55-1111111111--1111111111",
//     "10000000000000000010101010101010101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000308030803080308030801080108010801080108010101010101010101010-5-60-1-2800-4000-5000-50-1111111111--0011111100",
//     "00000010000010000000005090105090105090005090005090005090000000509010509010509000000000100000100000000000001000001000000000509010509010509000509000509000509000000050901050901050900000000010000010000000-1-60-1-2000-3500-4000-60-1111111111-4200441052015411450247125503571302040414050507159206941695079717-1111111111",
//     "00000000002000000000000000000020101010100000000000202080808000000000002010101010000000000020202020200000000000202020202000000000002010101010000000000020208080800000000000201010101000000000002000000000-0-60-1-2500-3500-4000-50-1111111111--1111111111",
//     "10000000004090909000100000000040909000001040404040409000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104040404040900000001000000000409090000010000000004090909000-1-60-1-2500-3500-4300-55-1111111111-39000110490111115902811269039113-1111111111",
//     "00000010101000000000001010100000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101000000000000000000010101000000000000000000010101000000000-3-80-0-3000-5000-6000-50-1111111111-4900301059016011390222126903721329041414790584151906061689079617-0000110000",
//     "00000000000020000030004040404020000080000040303040202000000000404030404040200020000040403030402020010000004040304040400100000000404030304002000000000040403040030000000000004040400400000000000000000003-0-80-0-3000-4000-4500-50-1111111111--1111111111",
//     "10101010101010101010000000001000000050500000000010000050509000000000100000505090000000001000005090800000000010000050908000000000100000505090000000001000005050900000000010000000505010101010101010101010-1-80-0-3000-4000-4500-55-1111111111-1300851023017511330265124303551353044514630535157306251683071517-1111111111",
//     "00000000001000000000000000000010000000000000000000100000000000000000001000000000101010101010101010101010101010101010101000000000100000000000002020201000202020000020202010002020200000000000100000000000-0-80-0-3000-4000-4500-55-1111111111-04006510140175112402851234039513690406147905161589062616990736170908601819097019290a801a390b901b-1111000000",
//     "00000000000000000000404040404040404040403030303030303030303040404040404040404040000000000000000000000000000000000000000040404040404040404040303030303030303030304040404040404040404000000000000000000000-0-80-0-2700-3200-3500-40-1111111111-39000010490110115902801269039013-0001111000",
//     "00000040808080808080000000408080808080800000004040404040408000000040202020204080000000402030302040800000004020303020408000000040202020204080000000404040404040800000004080808080808000000040808080808080-5-80-0-3000-3500-4000-50-1111111111--1111111111",
//     "00401000000000000000004010000000000000000040100000000000000000401010101000000000004040404010000000000000000040100000000000000000401010108080000000004040401080800000000000004010808000000000000040108080-5-80-0-4000-5000-6000-60-1111111111-01000310110113112102231231033613440446145405561564066816760778178608881896099819-1111111111",
//     "00100000100000100090001000001000001000904040400010000010009000004040404040404095505050505050505050905050505050505050509000004040404040404095404040001000001000900010000010000010009000100000100000100090-1-2700-1-1800-2500-3000-40-1111111111-00008210100192110302751213038513230495140605781516068816260798178008021890091219730a051a830b151b930c251c760d081d860e181e960f281f-1111111111",
//     "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010101010303030303000000080101020202020000000008010102020200000000000801010202000000000000080101020-5-80-0-4000-5000-6000-60-1111111111-69006010790170118902801299039013-1111100000",
//     "00000000000010101010003030303040001010100030202020204000101000302030303030400010003020302020202040000040203020303030400010004030203020202040101000402030203030401010100040402030208010101010000040408080-3-80-1-3500-4500-5000-60-1111111111--1111111111",
//     "00501000000000000000005010000000000000000050100000000000000010101010101010000000102020909090202020202020202090909020201000000010101010101010000000000000001050000000000000000010500000000000000000105000-1-60-1-4000-5000-6000-60-1111111111-01007810110188112102981279030313890413149905231509066016190770172908801839099019-1110000000",
//     "80808080808080808080202020202020202020200000000000000000000000100010001000100000102020201020202010101020202010202020101000100010001000100000000000000000000000002020202020202020202080808080808080808080-5-60-1-3000-5500-6000-70-1111111111-29000010390110116902801279039013-0011111100",
//     "00000000101010108060000000001010108060600000000010108060609000000000108060609090000000000060609090900000000000606090909000000000108060609090000000001010806060900000000010101080606000000000101010108060-1-1-1-3000-4500-5000-50-1111111111--1111111111",
//     "00000000000000000000000020202020202000000020303030303030200020303080808080303020203080808080808030202030808080808080302020303080808080303020002030303030303020000000202020202020000000000000000000000000-5-1-1-2000-2700-3200-50-1111111111--1111111111",
//     "00000000000000000000101010101010101010100000000000000000000010101010101010101010000000000000000000001010101010101010101010101010101010101010009090909090909090900090909090909090909000909090909090909090-1-1-1-2500-3700-4200-50-1111111111-090020102901401149028012-1000000000",
//     "00000000000000000030000000000000000030300000000000003030303000000010101010303030000000102000005050500000001020000050505000000010101010303030000000000000303030300000000000000000303000000000000000000030-1-1-1-2500-3700-4200-50-1111111111-4200441052015411-1111111111",
//     "00000010200020009090000000100020002090900000001020002000909020101010101010109090201000505050505090902010005050505050909020101010101010109090000000102000200090900000001000200020909000000010200020009090-1-1-1-2500-3700-4200-50-1111111111-12001410400142115002521282038413-1111111111",



//     "00000000000000000000000000002020202000000000000020b0b02000000000000020b0b020000000000000202020200000000000002020202000000000000020b0b02000000000000020b0b02000000000000020202020000000000000000000000000-6-1300-1-3000-4500-5000-60-1111111111--1111111111",
//     "00000000000030208080000000000000302020800000000000003030202000000000000000303030000000000000000000000000000000000000000000000000000000303030000000000000303020200000000000003020208000000000000030208080-5-1300-1-2500-3500-4500-60-1111111111--1111111111",
//     "00000000202020000000000020204040402020000020404040504040402000204050505050504020002040909050909040200020409090509090402000204050505050504020002040404050404040200000202040404020200000000000202020000000-1-1300-1-2000-2800-3300-40-1111111111--1111111111",
//     "00000000002030a0a0a00010101000002030a0a0000010101000002030a000000010101000002030000000001010100000202000000000101010000030200000000010101000a0302000000000101000a0a03020000000001000a0a0a030200000000000-3-60-2-3000-3500-4000-60-1111111111--1111111111",
//     "00000000000000000000200000000000000000002020001000201000002010200010002010000020101000100020100000201010001000201000002010200010002010000020202000100020100000202000000000000000000000000000000000000000-0-1300-1-3000-3800-4500-60-1111111111-22012711320237124203471352045714620567157206771629092419390a341a490b441b590c541c690d641d790e741e-1110000111",
//     "40200000000000000000404020000000700070002040402000000000000000204040200070007000000020404020000000000000002040402000000000000000204040200000000000000020404020000000000000002040402000000000000000204040-0-1300-1-3000-3800-4500-60-1111111111--1111111111",
//     "00000000101010100000000010005050105000000000000010101010000000001000505010500000000000001010101000000000100050501050000000000000101010100000000010005050505050500000000050505050505000001000505050505050-1-1300-1-3000-3800-4500-60-1111111111-150017103501371155025712-1111111111",
//     "00200020002000200020000020002000200020000020002000200020002000002000200010101001002000200020108302030000200020001084010400200020002010101003000020002000200020000020002000200020002000002000200020002000-4-5000-1-5000-6000-6500-70-1111111111--1111111111",
//     "101010101010101010101020302030203020301010302030203020302010102030203020302030101010101010101010101000000000a0a0a0a0a00000000000a006a006a00000000000a0a0a0a0a00000000000a006a006a00000000000a0a0a0a0a000-6-5000-1-3000-4000-4500-70-1111111111--0000011111",
//     "00000000000000000000000000000000000000001010101010101010101050501060601090909090505010606010909090905050106060109090909050501060601090909090101010101010101010100000000000000000000000000000000000000000-1-5000-1-3000-4000-5000-70-1111111111-09003010190140118902501299036013310433144105431551065316610763173408361844094619540a561a640b661b-1100000011",
//     "2020202020202020202030303030303030303030101010101010101010100000000000000000000000b0b000b0b000b0b00000b0b000b0b000b0b00000000000000000000000101010101010101010103030303030303030303020202020202020202020-6-5000-1-2500-3500-4000-60-1111111111--0001111000",
//     "00000000000050505050101010101010105050500000000000a0101050500000000000a0a01010100000000000a0a0a090900000000000a0a0a090900000000000a0a01010100000000000a0101050501010101010101050505000000000000050505050-1-5000-1-3000-4000-4500-70-1111111111-090020101901301129024012790350138904601499057015-1000000001",
//     "00505050505050505050005050505050505050501010101010101010101000000000000000000080000000000010100000800000007000001010008000000000000000101080000000000000000010100000007000007000000000000000000000000000-1-5000-1-3000-4000-4500-70-1111111111-8900001099011011-0001111111",
//     "0000000000000000000000b0b0b0b0b02020200000b0202020b02080200000b0208020b02020200000b0202020b0b0b0b00000b0b0b0b0202020b00000202020b0208020b00000208020b0202020b00000202020b0b0b0b0b00000000000000000000000-5-5000-1-3000-4500-5500-70-1111111111--1111111111",
//     "70000000000000000070000040404040404000000040000000000000400000400070303070004000004000303030300040000040003030303000400000400070303070004000004000000000000040000000404040404040000070000000000000000070-0-5000-1-4000-4500-5000-60-1111111111--1111111111",
//     "000000a0a00000a0a0000000a0a00000a0a0000000a0a00000a0a00000a0a0a00000a0a00000a0a0a00000a0a00000a0a0800000a0a00000a0a0808000a0a00000a0a08080a0a0a00000a0a08080a0a0a00000a0a08080a0a0000000a0a08080a0a00000-3-80-0-3500-4500-5000-60-1111111111--1111111111",
//     "00000070001050505050000000700010506060500000007000105060605000000070001050606050000000700010506060500000007000105060605000000070001050606050000000700010506060500000007000105060605000000070001050505050-1-80-0-4500-5500-6500-85-1111111111-04009610140186112402761234036613440456145405461564063616740726178408161894090619-1111111111",
//     "10101010101010101010101010101010101060601010101010606010606000106060106060106060001060601060601060600010606010606010606000106060106060100000001060601000000000000010000000000000000000000000000000000000-1-80-0-3500-4500-5000-70-1111111111-30003210400142115002521260036213700472143305251543063516530745176308551873096519260a181a360b281b460c381c560d481d660e581e-0001111111",
//     "000000002020202020200000000020b0b0a0b0b00000000020b0b0a0b0b000000000202020202020000000000000a0b0b020000000000000a0b0b020000000002020202020200000000020b0b0a0b0b00000000020b0b0a0b0b000000000202020202020-6-80-0-5000-6000-7000-75-1111111111--1111111111",
//     "2020202020202020202020b0b020b0b020b0b02020b0b020b0b020b0b020202020202020202020202020202020202020202020202020202020202020a0a0a0a0a0a0a0a0a0a0000000000000000000000000000000000000000000000000000000000000-6-80-0-4000-5000-6000-80-1111111111--1111111111",
//     "00001000000000100000000010000000001000000000100000000010000000001000000000100000101010000000000000001010100000000000000010101000000000007070101010000000007070701010100000000070707010101000000000007070-0-80-0-4000-5000-6000-80-1111111111-0100081011011811210228123103381309050315190613162907231739083318060b631b160c731c260d831d360e931e-1111100000",
//     "0000002070b000506090000000b00020705060900000002070b000506090000000b00020705060900000002070b000506090000000b00020705060900000002070b000506090000000b00020705060900000002070b000506090000000b0002070506090-1-80-0-5000-6000-7000-80-1111111111--1111111111",
//     "0000000000000000000010101010101010101010009090001010009090000090900010100090900010101010101010101010101010101010101010100090900010100090900000909000101000909000101010",
//     "70700000000000000000707070000000000000000070707000000000000000007070700000000000000000707070000000000000000070707000000000000000007070700000000000000000707070000000000000000070707000000000000000007070-3-80-3-4000-5000-6000-70-1111111111--1111111111",
//     "0000000000000000000000a0a02020a0a020200200a0a02020a0a0202001002020a0a02020a0a003002020a0a02020a0a08000a0a02020a0a020208000a0a02020a0a0202003002020a0a02020a0a001002020a0a02020a0a00200000000000000000000-0-80-3-4000-5000-6000-80-1111111111--1111111111",
//     "00004040404040404040000040a040b040a040b0000040b040a040b040a0000040a040b040a040b0000040b040a040b040a0000040a040b040a040b0000040b040a040b040a0000040a040b040a040b0000040b040a040b040a000004040404040404040-0-80-3-5000-6500-7500-80-1111111111--1111111111",
//     "20200000000000002020200000a0a0a0a00000200000a000000000a0000000a0000010100000a00000a0001020201000a00000a0001020201000a00000a0000010100000a0000000a000000000a00000200000a0a0a0a000002020200000000000002020-0-80-3-3000-4500-5500-70-1111111111--1111111111",
//     "00000000007000000070100000000000007000001010000000700000007000101000000000700000000010100070000000700000001010101010101000000000101010101010000000000010101010100000000000001010101000000000000000101010-0-80-3-3000-4500-5500-70-1111111111-96000010-0001111111",
//     "000000a0000050101010000000a0005050101000000000a000501010000010101010101010000000000000000000000000000000000000000000000010101010101010000000000000a0005010100000000000a0005050101000000000a0000050101010-1-80-3-3000-4500-5500-80-1111111111-190000102901101139022012690370137904801489059015-0000110000",
//     "00000000a0a0a0a0808000000000a0a0a000808000000000a0a0000000a00000003030000000a0a000002030000000a0a0a000202000000030a0a0a000000000003030000000000000002020000000000000000020000000000000000000000000000000-5-80-3-5000-6500-7500-85-1111111111--1111111111",
//     "00000010505050505050101010105050505050500000001010101010101010101010000000105050000000101010101050501010101000000010505000000010101010105050101010100000001050505050501010101010505050505010000000101010-1-80-3-5000-6500-7500-50-1111111111-02004010220160114202741262039413760434149605541536068016560790178208041892091419090a381a190b481b390c581c490d681d590e781e690f881f-1010000000",
//     "00000000000000a0a0a000000000000000a0a0a000000000202020a0a0a00000002020102020000000000020101010200000002020202010202000002020102020202000000020101010200000b0b0b020201020200000b070b000202020000000b0b0b0-6-80-3-4000-5500-6000-85-1111111111--1111111111",
//     "000000000000000000000000a0404040404040400000a0404040404040400070a0b040b040b040b00000a0404040404040400000a0404040404040400070a0b040b040b040b00000a0404040404040400000a04040404040404000000000000000000000-6-80-3-4000-5500-6000-70-1111111111--1111111111",
//     "00001000001010105050000010000010105090900000100000105090909000001000001050909090100010100010109090901000101000101090909000001000001050909090000010000010509090900000100000101050909000001000001010105050-1-80-3-3500-4500-5000-70-1111111111-01006010110170112102801231039013610463147105731581068316910793176408031874091319840a231a940b331b040c261c140d361d240e661e340f761f-1111000000",
//     "0000001000a0001000200000001000a0001000200000001000a0001000200000001000a0001000200000001000a00010002000000000000000000000b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b020202020202020202020-0-1-1-4000-5000-6000-70-1111111111-0200041012011411220224123203341306040814160518152606281636073817-1111111111",
//     "90909090909090909090901000a0a070b0709090901000a0a0b070b09090901000a0a070b0709090901000a0a0b070b09090901000a0a070b0709090901000a0a0b070b09090901000a0a070b0709090901000a0a0b070b0909090909090909090909090-1-1-1-6000-8000-9500-100-1111111111-1000121020012211300232124003421350045214600562157006721680078217-1111111111"


// ];
//{"version":1111,"moves":4418,"bonuses":2505,"levels":[{"c":2,"s":3,"p":1630},{"c":2,"s":3,"p":1460},{"c":2,"s":3,"p":2770},{"c":2,"s":3,"p":5260},{"c":2,"s":2,"p":3400},{"c":2,"s":3,"p":3720},{"c":2,"s":3,"p":6520},{"c":2,"s":3,"p":4350},{"c":2,"s":3,"p":6250},{"c":2,"s":3,"p":3060},{"c":2,"s":3,"p":4670},{"c":2,"s":1,"p":2400},{"c":2,"s":3,"p":6850},{"c":2,"s":3,"p":4750},{"c":2,"s":3,"p":7110},{"c":2,"s":2,"p":3770},{"c":2,"s":3,"p":7310},{"c":2,"s":1,"p":4040},{"c":2,"s":2,"p":3180},{"c":2,"s":2,"p":5600},{"c":2,"s":3,"p":4920},{"c":2,"s":3,"p":5180},{"c":2,"s":3,"p":5370},{"c":2,"s":3,"p":5180},{"c":2,"s":3,"p":4200},{"c":2,"s":2,"p":3680},{"c":2,"s":3,"p":3620},{"c":2,"s":3,"p":8640},{"c":2,"s":1,"p":2420},{"c":2,"s":1,"p":2430},{"c":2,"s":3,"p":6390},{"c":2,"s":3,"p":6020},{"c":2,"s":2,"p":3800},{"c":2,"s":3,"p":5270},{"c":2,"s":3,"p":6840},{"c":2,"s":3,"p":5300},{"c":2,"s":3,"p":22800},{"c":2,"s":2,"p":3830},{"c":2,"s":1,"p":3150},{"c":2,"s":3,"p":5570},{"c":2,"s":2,"p":3750},{"c":2,"s":3,"p":4320},{"c":2,"s":3,"p":5660},{"c":2,"s":2,"p":4350},{"c":2,"s":3,"p":2700},{"c":2,"s":3,"p":5740},{"c":2,"s":1,"p":2300},{"c":2,"s":2,"p":2780},{"c":2,"s":3,"p":2210},{"c":2,"s":3,"p":4210},{"c":2,"s":3,"p":4540},{"c":2,"s":3,"p":3450},{"c":2,"s":3,"p":3980},{"c":2,"s":3,"p":4170},{"c":2,"s":3,"p":3770},{"c":2,"s":3,"p":4780},{"c":2,"s":2,"p":3350},{"c":2,"s":3,"p":5850},{"c":2,"s":3,"p":5740},{"c":2,"s":3,"p":6400},{"c":2,"s":2,"p":4770},{"c":2,"s":2,"p":3150},{"c":2,"s":2,"p":4590},{"c":2,"s":3,"p":2670},{"c":2,"s":2,"p":4930},{"c":2,"s":1,"p":3540},{"c":2,"s":3,"p":4440},{"c":2,"s":3,"p":9310},{"c":2,"s":3,"p":5900},{"c":2,"s":3,"p":6690},{"c":2,"s":2,"p":7410},{"c":2,"s":3,"p":5720},{"c":2,"s":1,"p":3760},{"c":2,"s":2,"p":4960},{"c":1,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0},{"c":0,"s":0,"p":0}]}
export class LevelData {
    constructor(lvl, data, state) {
        if (typeof state === "undefined") {
            state = 0;
        }
        this.state = 0;
        this.stars = 0;
        this.score = 0;
        this.pushPositions = [];
        this.hasWhiteChoco = false;
        this.hasBlackChoco = false;
        this.hasBomb = false;
        this.teleportData = [];
        this.data = data;
        if (!this.data)
            this.data = e.defaultData;
        this.state = state;
        this.levelNumber = lvl;
        this.stars = 0;
        for (var i = 0; i < GameConst.LEVEL_W; ++i)
            this.pushPositions.push(i);
        var cfgArr = this.data.split("-");
        this.cellData = cfgArr[0];
        this.targetData = parseInt(cfgArr[1]);
        this.customData = parseInt(cfgArr[2]);
        this.customData2 = parseInt(cfgArr[3]);
        this.movesLeft = parseInt(cfgArr[7]);
        this.starValues = [parseInt(cfgArr[4]), parseInt(cfgArr[5]), parseInt(cfgArr[6])];
        this.pushPositionStr='';
        if (cfgArr.length > 8) {
            
            this.pushPositions = [];
            var o = cfgArr[8];
            this.pushPositionStr = o;
            for (var j = 0; j < o.length && j < GameConst.LEVEL_W; ++j)
                if (parseInt(o.charAt(j)) == 1)
                    this.pushPositions.push(j);
        }
        this.teleportStr = '';
        if (cfgArr.length > 9) {
            var teleportStr = cfgArr[9];
            this.teleportStr = teleportStr;
            for (var u = 0; u < teleportStr.length; u += 4) {
                var f = [];
                for (var i = 0; i < 4; i++)
                    f.push(i < 3 ? parseInt(teleportStr[u + i]) : LevelData.cellCodes.indexOf(teleportStr[u + i]));
                this.teleportData.push(f);
            }
        }
        this.jellyPushStr='';
        if (cfgArr.length > 10) {
            this.jellyPushPositions = [];
            var tstr = cfgArr[10];
            this.jellyPushStr=tstr;
            for (u = 0; u < o.length && u < GameConst.LEVEL_W; ++u){
                this.jellyPushPositions.push(parseInt(tstr.charAt(u)) == 1);
            }
        }
        for (var i = 0; i < GameConst.LEVEL_W; ++i) {
            for (var c = 0; c < GameConst.LEVEL_H; ++c) {
                var h = Utils.getCellDataType(this.cellData, i, c);
                if (h == "2")
                    this.hasWhiteChoco = true;
                if (h == "3")
                    this.hasBlackChoco = true;
                if (h == "7")
                    this.hasBomb = true;
            }
        }
        switch (this.targetData) {
            case 0:
                this.targetSpriteName = "chocolate white";
                break;
            case 1:
                this.targetSpriteName = "cookie";
                break;
            case 2:
                this.targetSpriteName = "cupcake";
                break;
            case 3:
                this.targetSpriteName = FieldObject.assetNames[this.customData2];
                break;
            case 4:
                this.targetSpriteName = "star";
                break;
            case 5:
                this.targetSpriteName = "water";
                break;
            case 6:
                this.targetSpriteName = "bush";
                break;
            case -1:
                this.targetSpriteName = "star";
                break
        }
    }
}
LevelData.prototype.getCakeSpawnPos = function () {
    var e = Utils.getInt(this.pushPositions.length);
    return this.pushPositions[e];
};

LevelData.defaultData = "=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000-4-99999-1-500-1500-3000-99";
LevelData.cellCodes = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h"];